function find(){
    let pageNum = $("#inputPageNum").val().trim()
    console.log(pageNum)
    if(null == pageNum || pageNum ==""){
        layer.msg("请输入快递编号！")
    }else if(pageNum.length != 9){
        layer.msg("快递编号为9位纯数字！")
    }else {
        $.ajax({
            url: url + "/userPageInfo/selectOption",
            dataType: "json",
            data: "pageNum=" + pageNum,
            type: "post",
            success: function (data) {
                console.log(data)
                if (1 == data.code) {
                    layer.msg("查询快递位置成功！")

                    $("#provice option[value='"+ data.data.nowProvince +"']").attr("selected",true);
                    // var select1 = document.getElementById("province")
                    // for( let i=0;i< select1.length; i++){
                    //     if(select1.options[i].innerHTML==data.data.nowProvince){
                    //         select1.options[i].selected=true;
                    //         break;}
                    // }
                    //
                    // var select2 = document.getElementById("city")
                    // for( let i=0;i< select2.length; i++){
                    //     if(select2.options[i].innerHTML==data.data.nowCity){
                    //         select2.options[i].selected=true;
                    //         break;}
                    // }
                    //
                    // var select3 = document.getElementById("area")
                    // for( let i=0;i< select3.length; i++){
                    //     if(select3.options[i].innerHTML==data.data.nowArea){
                    //         select3.options[i].selected=true;
                    //         break;}
                    // }

                } else {
                    layer.msg("查询快递位置是失败！")
                }
            }
        })
    }
}

function update(){
    var pageNum = $("#inputPageNum").val()
    var province = document.getElementById("province").value;
    var city = document.getElementById("city").value
    var area = document.getElementById("area").value

    if(null == pageNum || pageNum ==""){
        layer.msg("请输入快递编号！")
    }else if(pageNum.length != 9){
        layer.msg("快递编号为9位纯数字！")
    }else {
        $.ajax({
            url: url + "/userPageInfo/selectOption",
            dataType: "json",
            data: "pageNum=" + pageNum,
            type: "post",
            success: function (data) {
                console.log(data)
                var endProvince = data.data.endProvince
                var endCity = data.data.endCity
                var endArea = data.data.endArea
                $.ajax({
                    url: url + "/userPageInfo/selectPageStatus",
                    dataType: "json",
                    data: "pageNum=" + pageNum,
                    type: "post",
                    success: function (data) {
                        if("运输中" == data.data.status ||"已完成" == data.data.status){
                            if(null == province){
                                layer.msg("还没选省份哦！")
                            }else {
                                $.ajax({
                                    url: url + "/userPageInfo/updateNowOption",
                                    dataType: "json",
                                    data: "pageNum=" + pageNum + "&province=" + province + "&city=" + city + "&area=" + area,
                                    type: "post",
                                    success: function (data) {
                                        console.log(data)
                                        if(1 == data.code){
                                            if(province == endProvince && city == endCity && area == endArea){
                                                layer.msg("检测到该快递已到达目的地,已向收件人发送取件码短信")
                                                return
                                            }
                                            layer.msg("修改快递位置成功！")
                                            $("#inputPageNum").val("")
                                        }else{
                                            layer.msg("修改快递位置失败！")
                                        }
                                    }
                                })
                            }
                        }else {
                            layer.msg("该快递不可以更改地址哦！")
                        }
                    }
                })
            }
        })
    }
}